package com.atlas.alpha;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class SchedulerActivity extends Activity {

	private Button btnAddToCal;
	private Button btnClear;
	private EditText etDate;
	private EditText etStartTime;
	private EditText etEndTime;

	
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_scheduler);
        
        btnAddToCal = (Button)findViewById(R.id.btnAddToCal);
        btnClear = (Button)findViewById(R.id.btnClear);
        etDate = (EditText)findViewById(R.id.etDate);
        etStartTime = (EditText)findViewById(R.id.etStartTime);
        etEndTime = (EditText)findViewById(R.id.etEndTime);
        
        Calendar cal = Calendar.getInstance();
		SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
        String strDate = sdf.format(cal.getTime());
       
        etDate.setText(strDate);
        StringBuilder sb = new StringBuilder();
        //StringBuilder sb2 = new StringBuilder();
        Date date = new Date();
       // Date dateHourLater = new Date();
        sb.append(date.getHours() + ":" + date.getMinutes());
       //  dateHourLater.setHours(date.getHours() + 1);
       // sb2.append(dateHourLater.getHours() + ":" + date.getMinutes());
        etStartTime.setText(sb.toString());
        etEndTime.setText(sb.toString());
        //add workout to call
        btnAddToCal.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
            	Calendar cal = Calendar.getInstance();              
            	Intent intent = new Intent(Intent.ACTION_EDIT);
            	intent.setType("vnd.android.cursor.item/event");
            	intent.putExtra("beginTime", etStartTime.getText());
            	intent.putExtra("allDay", true);
            	intent.putExtra("endTime", etEndTime.getText());
            	intent.putExtra("title", "Atlas Scheduled Workout");
            	startActivity(intent);
            }
        });
        btnClear.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
            	etDate.setText("");
            	etStartTime.setText("");
            	etEndTime.setText("");
            }
        });

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_scheduler, menu);
        return true;
    }
}
